<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    	<title>统战成员学习平台</title>
	    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
	    <link rel="stylesheet" type="text/css" href="../../css/discovery.css" />
	    <link rel="stylesheet" type="text/css" href="../../script/WebUploader/css/webuploader.css" />
	</head>
	<body>
		<div id='app' class="user_profile" style="display:none" v-show="true">
			<div class="user_form">
				<div class="item head right" style="display: flex; justify-content: space-between">
					头像
					<span id="filePicker" style="float: none;display: inline-flex;">
						<img :src="imageBasePath + userInfo.usrImg" onerror="this.src='../../image/default_head.png'">
					</span>
				</div>
				<div class="item ui_border_t">
					姓名<span>{{userInfo.usrName}}</span>
				</div>
				<div class="item ui_border_t">
					性别<span>{{userInfo.usrSex}}</span>
				</div>
				<div class="item ui_border_t">
					出生日期<span>{{userInfo.usrBirthday}}</span>
				</div>
				<div tapmode="tap" @click="openWin('update_phone_win')" class="item right ui_border_t">
					联系方式<span>{{userInfo.usrPhone}}</span>
				</div>
				<div tapmode="tap" @click="openWin('update_email_win')" class="item right ui_border_t">
					邮箱<span>{{userInfo.usrEmail}}</span>
				</div>
				<div class="item ui_border_t">
					党派团体<span style="width:13rem;text-align: right;">{{userInfo.usrPartycommitteeName}}</span>
				</div>
				<div class="item ui_border_t">
					支部名称<span style="width:13rem;text-align: right;">{{userInfo.branchName}}</span>
				</div>
				<div class="item ui_border_t">
					一级单位<span style="width:13rem;text-align: right;">{{userInfo.firstUnitName}}</span>
				</div>
				<div class="item ui_border_t">
					二级单位<span style="width:13rem;text-align: right;">{{userInfo.secondUnitName}}</span>
				</div>
				<div class="item ui_border_t">
					政治面貌<span style="width:13rem;text-align: right;">{{userInfo.politicalStatusName}}</span>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="../../script/api.js"></script>
		<script type="text/javascript" src="../../script/vue.min.js"></script>
		<script type="text/javascript" src="../../script/common.js"></script>
		<script type="text/javascript" src="../../script/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="../../script/WebUploader/js/webuploader.min.js"></script>
		<script type="text/javascript" src="../../script/layer_mobile/layer.js"></script>
		<script type="text/javascript">
			var uploader;
		    new Vue({
				el: '#app',
		     	data: {
					userInfo : {}
		     	},
				mounted: function() {
		        	var $this = this;
		        	apiready = function() {
						api.parseTapmode();

						$this.init();
						api.addEventListener({
						    name: 'refresh_userInfo_event'
						}, function(ret, err){
						    $this.userInfo = $api.getStorage(_.USERINFO) || {};
						});


                	}
		    	},
		    	methods: {
					init: function() {
						var $this = this;
						$this.userInfo = $api.getStorage(_.USERINFO) || {};

						setTimeout(function () {
							$this.uploaderInit();
						}, 500);
					},
					uploaderInit: function () {
						var $this = this;
						var data = {};
						var userInfo = $api.getStorage(_.USERINFO);
						if (userInfo) {
							data.userId = userInfo.usrId;
							data.time = Date.now();
							data.encodeToken = MD5(data.time + userInfo.mobileToken + userInfo.mobileVerifyKey);
							data.requestType = 'partyconstruction_app';
						}

						uploader = WebUploader.create({
							formData: data,
							// 选完文件后，是否自动上传。
							auto: true,

							// swf文件路径
							swf: '../../script/WebUploader/Uploader.swf',

							// 文件接收服务端。
							server: basePath + '/client/user/updateUserImg',

							// 选择文件的按钮。可选。
							// 内部根据当前运行是创建，可能是input元素，也可能是flash.
							pick: '#filePicker',

							// 只允许选择图片文件。
							accept: {
								title: 'Images',
								extensions: 'gif,jpg,jpeg,bmp,png',
								mimeTypes: 'image/*'
							},
							method: 'POST',
							compress: {
								width: 100,
								height: 100,

								// 图片质量，只有type为`image/jpeg`的时候才有效。
								quality: 90,

								// 是否允许放大，如果想要生成小图的时候不失真，此选项应该设置为false.
								allowMagnify: false,

								// 是否允许裁剪。
								crop: false,

								// 是否保留头部meta信息。
								preserveHeaders: true,

								// 如果发现压缩后文件大小比原来还大，则使用原来图片
								// 此属性可能会影响图片自动纠正功能
								noCompressIfLarger: false,

								// 单位字节，如果图片大小小于此值，不会采用压缩。
								compressSize: 1 * 1024 * 1024
							},
							fileSingleSizeLimit: 5 * 1024 * 1024    // 50 M
						});

						// 文件上传成功，给item添加成功class, 用样式标记上传成功。
						uploader.on('uploadSuccess', function (file, data) {
							msgUtil.message('上传成功');

							if (data.isSuccess && data.data) {
								api.sendEvent({
									name: 'refresh_userInfo_event'
								});
								$this.userInfo.usrImg = data.data;

								$('.webuploader-pick img').attr('src', imageBasePath + $this.userInfo.usrImg)

							}

						});

						// 文件上传失败，显示上传出错。
						uploader.on('uploadError', function (file) {
							msgUtil.message('上传失败');
						});
					}
		    	}
		    });
		</script>
	</body>
</html>
